"use strict";

/**
 * @ngdoc filter
 * @name jgappApp.filter:fileName
 * @function
 * @description
 * # fileName
 * Filter in the jgappApp.
 */
angular
  .module("jgappApp")
  .filter("fileName", function() {
    return function(input) {
      if (input) {
        return input.slice(input.indexOf("_") + 1);
      }
    };
  })
  .filter("showimg", function(openApi) {
    return function(input) {
      if (input) {
        var signStr=NativeUtil.getSignStr()
        return openApi.showimg + "?imgUrl=" + input + "&" +signStr;
      }
    };
  })
  .filter("ifimg", function(openApi) {
    return function(input) {
      if (input) {
        return /(.+)\.(jpg|png|gif|jpeg)$/gi.test(input);
      }
    };
  })
  .filter("iffile", function(openApi) {
    return function(input) {
      if (input) {
        return /(.+)\.(docx|ppt|doc|xls|zip|rar|xlsx|et|pptx|pdf|wps|txt|pub)$/gi.test(
          input
        );
      }
    };
  })
  .filter("userinfo", function(localStorageService) {
    return function(input, key) {
      var data = localStorageService.get("ContactInfo");
      if (input && data) {
        var user={};
        data.some(function(item, index) {
          if (item.children) {
            var check = item.children.some(function(subitem, index) {
              user = subitem;
              return subitem.id == input;
            });
            return check;
          }
        });
        return user[key];
      } else {
        return input;
      }
    };
  })
  .filter("aduituserfilter", function() {
    return function(input) {
      var numberSymbols = [ '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩','⑪','⑫','⑬','⑭','⑮','⑯','⑰','⑱','⑲','⑳' ];
      function formatUsersContent (v) {
        if (v) {
          var str = '',symbols;
          v.split(',').forEach(function (item, index) {
            symbols = numberSymbols[index] || (index + 1);
            str = str + ' ' + symbols + item;
          });
          return  str;
      
        } else {
          return v;
        }
      }
      
      if (input) {        
        return  formatUsersContent(input);
      } else {
        return input;
      }
    };
  });